<?php
/*
 * Delete a comment.
 */

// authenticate user first
F3::call('authentication.php');
if (F3::exists('auth_error'))
{
  	header('HTTP/1.1 500 Internal Server Error');
	header("Content-Type: application/json");
	$err = array("error_message" => "User is not authenticated.");
	echo json_encode($err);
	return;
}

if (!F3::exists("PARAMS['recipe_id']") || !F3::exists("POST.timestamp")):
	header('HTTP/1.1 500 Internal Server Error');
	header("Content-Type: application/json");
	$err = array("error_message" => "Recipe id and timestamp required.");
	echo json_encode($err);
	return;
endif;

// setup params
$id = F3::get('SESSION.user_id');
$rid = F3::get("PARAMS['recipe_id']");
$timestamp = F3::get("POST.timestamp");

// delete comment
$param = array('1'=>$id, '2'=>$rid, '3'=>$timestamp);
DB::sql("delete from comments where uid = ? and rid = ? and timestamp = ?",$param);

// success
header('HTTP/1.1 204');
header("Content-Type: application/json");
$response = "Comment deleted.";
echo json_encode($response);
return;
?>
